﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Win7Helper.Helper
{
    class XmlHelper
    {
        /// <summary>
        /// 获取xml的内容
        /// </summary>
        /// <param name="XmlValue">xml的文本信息</param>
        /// <param name="XmlPath">xpath路径</param>
        /// <returns></returns>
        public static List<string> SelectNode(string XmlValue, String XmlPath)
        {
            List<String> ValueList = new List<string>();
            XmlDocument xmlDoc = new XmlDocument();
            try
            {
                xmlDoc.LoadXml(XmlValue);
                //取根结点
                XmlElement root = xmlDoc.DocumentElement;//取到根结点


                //取指定的结点的集合
                XmlNodeList nodes = xmlDoc.SelectNodes(XmlPath);


                foreach (XmlNode line in nodes)
                {
                    ValueList.Add(line.InnerText);
                }
            }
            catch (Exception ex)
            {
                PrintLog.Log(ex);
            }
            return ValueList;
        }
        /// <summary>
        /// 获取第一个值并且返回的方法
        /// </summary>
        /// <param name="xmlNodeList"></param>
        /// <returns></returns>
        public static String GetFirstValue(List<string> xmlNodeList) {
            string text = "";
            foreach (String line in xmlNodeList)
            {//如果有值，第一个就结束了，如果没有，那就进不来for循环
                return line;
            }
            return text;

        }
    }
}
